<?php


class WSB_Controller_Plugin_Messenger extends Zend_Controller_Plugin_Abstract
{
    /**
     * Called before an action is dispatched by Zend_Controller_Dispatcher.
     *
     * This callback allows for proxy or filter behavior.  By altering the
     * request and resetting its dispatched flag (via
     * {@link Zend_Controller_Request_Abstract::setDispatched() setDispatched(false)}),
     * the current action may be skipped.
     *
     * @param  Zend_Controller_Request_Abstract $request
     * @return void
     */
    public function postDispatch(Zend_Controller_Request_Abstract $request)
    {
		// FlashMessenger
		$flashMessenger = new Zend_Controller_Action_Helper_FlashMessenger();
		$messages = array();
		if($flashMessenger->hasCurrentMessages()) {
			$messages = $flashMessenger->getCurrentMessages();
			$flashMessenger->clearMessages();
			$session = new Zend_Session_Namespace('FlashMessenger');
			unset($session);
		}
		elseif($flashMessenger->hasMessages()) {
			$messages = $flashMessenger->getMessages();
		}
		$htmlMessages = '';
		if(count($messages) > 0) {
			$htmlMessages = sprintf('<div class="success">%s</div>',
				implode(', ', $messages)
			);
		}
		$this->getResponse()->append('messages', $htmlMessages);
    }

}
